// pages/bigSales/bigSales.js
import { Classify } from '../../utils/url.js';
import { search } from '../../utils/url.js';

Page({

    /**
     * 页面的初始数据
     */
    data: {
        searchNum:1,
        className:"",
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        var className = options.className;
        var searchNum = that.data.searchNum;
        that.setData({
            className: className,
        })
        wx.request({
            url: Classify.Classify,
            method: 'get',
            data: {
                className: className,
                searchNum: searchNum
            },
            header: {
                'Accept': 'application/json'
            },
            success: function (res) {
                console.log(res)
                that.setData({
                    adviceItems: res.data.result.list
                })
            }
        })
    },
    //   下拉加载
    onReachBottom: function () {
        var that = this;
        var searchNum = 1;
        var className = that.data.className;
        console.log('--------下拉刷新-------')
        wx.showNavigationBarLoading() //在标题栏中显示加载
        wx.request({
            url: Classify.Classify,
            data: {
                searchNum: searchNum,
                className: className,
            },
            method: 'get',
            success: function (res) {
                for (var i = 0; i < res.data.result.list.length; i++) {
                    adviceItems.push(res.data.result.list[i]);
                }
                console.log(res.data.length);
                searchNum++;
                that.setData({
                    adviceItems: adviceItems,
                    searchNum: searchNum
                })
            },
            fail: function () {
                console.log('呀！传输失败了哦')
            },
            complete: function () {
                wx.hideNavigationBarLoading() //完成停止加载
                wx.stopPullDownRefresh() //停止下拉刷新
            }
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})